package com.itheima.tanhua.member.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.tanhua.base.common.BaseContext;
import com.itheima.tanhua.base.common.Result;
import com.itheima.tanhua.base.entity.TdlFollow;
import com.itheima.tanhua.member.mapper.TdlFollowMapper;
import com.itheima.tanhua.member.service.TdlFollowService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 关注表 服务实现类
 * </p>
 *
 * @author yangjiahao
 * @since 2023-01-31
 */
@Service
public class TdlFollowServiceImpl extends ServiceImpl<TdlFollowMapper, TdlFollow> implements TdlFollowService {

    @Override
    public Result like(String userId) {
        String id = BaseContext.getCurrentId();
        TdlFollow tdlFollow = new TdlFollow();
        tdlFollow.setMemberId(id);
        tdlFollow.setFollowId(userId);
        save(tdlFollow);
        return Result.success("关注成功");
    }

    @Override
    public Result disLike(String userId) {
        LambdaQueryWrapper<TdlFollow> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TdlFollow::getFollowId,userId);
        remove(wrapper);
        return Result.success("取关成功");
    }
}
